# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=cargo-c
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.6.10
pkgrel=1
pkgdesc='A cargo subcommand to build and install C-ABI compatibile dynamic and static libraries (mingw-w64)'
arch=('any')
url='https://github.com/lu-zero/cargo-c/'
license=('MIT')
depends=(
    "${MINGW_PACKAGE_PREFIX}-curl"
    "${MINGW_PACKAGE_PREFIX}-openssl"
    "${MINGW_PACKAGE_PREFIX}-libgit2"
    "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=(
    "${MINGW_PACKAGE_PREFIX}-rust")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/lu-zero/cargo-c/archive/v${pkgver}.tar.gz"
        "${_realname}-${pkgver}.Cargo.lock"::"https://github.com/lu-zero/cargo-c/releases/download/v${pkgver}/Cargo.lock")
sha256sums=('3e0f6c70291e48b09f936a5918656159b1d840d7a3b010316d0fc61e9b048bca'
            '3959b780a22afa6d9ac2a620fce6c1601957bfec465afd204e0db40b5693bc09')

prepare() {
    cp "${srcdir}/${_realname}-${pkgver}.Cargo.lock" "${_realname}-${pkgver}/Cargo.lock"
    cd "${srcdir}/${_realname}-${pkgver}"

    cargo fetch \
        --locked
}

build() {
    cd "${srcdir}/${_realname}-${pkgver}"

    cargo build \
        --release \
        --frozen \
        --offline
}

check() {
    cd "${srcdir}/${_realname}-${pkgver}"

    cargo test \
        --release \
        --frozen
}

package() {
    cd "${srcdir}/${_realname}-${pkgver}"

    cargo install \
    --frozen \
    --offline \
    --no-track \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

    install -D -m644 "LICENSE" -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
